home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / graphic / fgdemo10.zip / MISC.C < prev    next >
Text File  |  1991-10-02  |  14KB  |  546 lines

  1. /**********************************************************************\
  2. *                                                                      *
  3. *  misc.c -- sound, music, editor, etc. -- things on the MISC menu     *
  4. *                                                                      *
  5. \**********************************************************************/
  6.  
  7. #include "defs.h"
  8.  
  9. /**********************************************************************\
  10. *                                                                      *
  11. *  do_editor -- call the editor                                        *
  12. *                                                                      *
  13. \**********************************************************************/
  14.  
  15. do_editor()
  16. {
  17.    char *array;
  18.    int array_len;
  19.  
  20.    /* allocate a string to pass to the editor function */
  21.  
  22.    array = calloc(10000,sizeof(char));
  23.    if (array == NULL)
  24.       return(ERR);
  25.  
  26.    /* define a black background */
  27.  
  28.    background = 0;
  29.  
  30.    /* clear the screen */
  31.  
  32.    fg_mousevis(OFF);
  33.    fg_restore(0,xlimit,menu_bottom,ylimit);
  34.  
  35.    /* draw the box */
  36.  
  37.    fg_setcolor(0);
  38.    fg_rect(144,487,50,180);
  39.    fg_setcolor(15);
  40.    fg_rect(144,487,181,195);
  41.    fg_setcolor(0);
  42.    fg_rect(144,487,196,196);
  43.    center_pstring("Press F1 for help, Esc to exit",150,490,195);
  44.  
  45.    /* call the editor function */
  46.  
  47.    fg_setcolor(15);
  48.    editor(array,148,485,53,180,20,&array_len);
  49.  
  50.    /* redraw the screen */
  51.  
  52.    draw_screen();
  53.    fg_restore(0,xlimit,0,ylimit);
  54.    highlight_option(4);
  55.    fg_mousevis(ON);
  56.  
  57.    /*******************************************************************
  58.  
  59.    This editor is included for demonstration purposes only, and does
  60.    not write anything out to a file.  If you were going to write the
  61.    text to a text file, you would probably want to do something like
  62.    this:
  63.  
  64.    index = 0;
  65.    for (i = 0; i < 20; i++)
  66.    {
  67.       nchar = strlen(&array[index]);
  68.       fprintf(stream,"%s\n",&ver_array[index]);
  69.       index+=nchar;
  70.       index+=2;
  71.  
  72.       if (index >= array_len)
  73.          break;
  74.    }
  75.  
  76.    Notice that the array is a collection of null terminated strings.
  77.    Be sure to free the array when you are done.
  78.  
  79.    *******************************************************************/
  80.  
  81.    free(array);
  82.    redraw = TRUE;
  83.  
  84.    return(OK);
  85. }
  86.  
  87. /**********************************************************************\
  88. *                                                                      *
  89. *  do_histogram -- create a histogram                                  *
  90. *                                                                      *
  91. \**********************************************************************/
  92.  
  93. do_histogram()
  94. {
  95.    register int i;
  96.    int x1,x2,y1,y2;
  97.    static char label[] = "Productivity";
  98.    static char title[] = "See profits soar with Fastgraph!";
  99.  
  100.    static int x[] = {130, 180, 230, 280, 330, 380, 430, 480};
  101.    static int y[] = {290, 275, 270, 265, 200, 170, 130, 100};
  102.  
  103.    /* clear the bottom of the screen */
  104.  
  105.    fg_mousevis(OFF);
  106.    fg_restore(0,xlimit,menu_bottom,ylimit);
  107.  
  108.    fg_setpage(visual);
  109.    fg_setcolor(0);
  110.  
  111.    y1 = scale(100);
  112.    y2 = scale(300);
  113.  
  114.    /* axes */
  115.  
  116.    fg_rect(120,520,y2,y2);
  117.    fg_rect(120,120,y1,y2);
  118.  
  119.    for (i = 100; i < 300; i+=20)
  120.    {
  121.       y1 = scale(i);
  122.       fg_rect(120,126,y1,y1);
  123.    }
  124.  
  125.    /* boxes */
  126.  
  127.    for (i = 0; i < 8; i++)
  128.    {
  129.       x1 = x[i];
  130.       x2 = x1 + 30;
  131.       y1 = scale(y[i]);
  132.  
  133.       fg_setcolor(11);
  134.       fg_rect(x1,x2,y1,y2);
  135.  
  136.       fg_setcolor(0);
  137.       draw_box(x1,x2,y1,y2);
  138.    }
  139.  
  140.    /* label the x axis */
  141.  
  142.    x1 = 320 - length_pstring(label)/2 - 2;
  143.    x2 = 320 + length_pstring(label)/2 + 2;
  144.    y2 = scale(320);
  145.    y1 = y2 - ptsize - 1;
  146.    if (mode06 || mode11)
  147.    {
  148.       fg_setcolor(15);
  149.       fg_rect(x1,x2,y1,y2);
  150.    }
  151.    fg_setcolor(0);
  152.    center_pstring(label,x1,x2,y2);
  153.  
  154.    /* Profits soar with Fastgraph */
  155.  
  156.    x1 = 320 - length_pstring(title)/2 - 2;
  157.    x2 = 320 + length_pstring(title)/2 + 2;
  158.    y2 = scale(90);
  159.    y1 = y2 - ptsize - 1;
  160.    if (mode06 || mode11)
  161.    {
  162.       fg_setcolor(15);
  163.       fg_rect(x1,x2,y1,y2);
  164.    }
  165.    fg_setcolor(0);
  166.    center_pstring(title,x1,x2,y2);
  167.  
  168.    /* wait for a keystroke or mouse button */
  169.  
  170.    fg_mousevis(ON);
  171.    wait_for_keystroke();
  172.  
  173.    /* restore the screen and return to the menu */
  174.  
  175.    fg_restore(0,xlimit,menu_bottom,ylimit);
  176.    redraw = TRUE;
  177.  
  178.    return(OK);
  179. }
  180.  
  181. /**********************************************************************\
  182. *                                                                      *
  183. *  do_joystick -- demo some joystick functions                         *
  184. *                                                                      *
  185. \**********************************************************************/
  186.  
  187. do_joystick()
  188. {
  189.    static char *string1[] = {
  190.    "Joystick",
  191.    "Joysticks found on Port 1 and Port 2."
  192.    };
  193.  
  194.    static char *string2[] = {
  195.    "Joystick",
  196.    "Joystick found on Port 1."
  197.    };
  198.  
  199.    static char *string3[] = {
  200.    "Joystick",
  201.    "Joystick found on Port 2."
  202.    };
  203.  
  204.    static char *string4[] = {
  205.    "Joystick",
  206.    "Joystick not found."
  207.    };
  208.  
  209.    static int joy1_x[] = {140,200,260,140,200,260,140,200,260};
  210.    static int joy2_x[] = {360,420,480,360,420,480,360,420,480};
  211.    static int joy_y[] =  {110,110,110,140,140,140,170,170,170};
  212.  
  213.    unsigned char key,aux;
  214.    int x,y;
  215.    int count,mousex,mousey;
  216.    int pos1,pos2,new_pos1,new_pos2;
  217.    int joystick[2];
  218.  
  219.    /* initialize joysticks, if possible */
  220.  
  221.    if (fg_initjoy(1) == 0)
  222.       joystick[0] = TRUE;
  223.    else
  224.       joystick[0] = FALSE;
  225.  
  226.    if (fg_initjoy(2) == 0)
  227.       joystick[1] = TRUE;
  228.    else
  229.       joystick[1] = FALSE;
  230.  
  231.    fg_mousevis(OFF);
  232.    fg_restore(0,xlimit,menu_bottom,ylimit);
  233.  
  234.    /* report status of joysticks */
  235.  
  236.    if (joystick[0] && joystick[1])
  237.       info_window(120,520,45,string1,2);
  238.    else if (joystick[0])
  239.       info_window(120,520,45,string2,2);
  240.    else if (joystick[1])
  241.       info_window(120,520,45,string3,2);
  242.    else
  243.       info_window(120,520,45,string4,2);
  244.  
  245.    /* draw a grid to illustrate joystick positions */
  246.  
  247.    fg_mousevis(OFF);
  248.    if (joystick[0])
  249.    {
  250.       fg_setcolor(15);
  251.       fg_rect(120,300,100,190);
  252.       fg_setcolor(0);
  253.       draw_box(120,300,100,190);
  254.       draw_box(180,240,100,190);
  255.       draw_box(120,300,130,160);
  256.    }
  257.  
  258.    if (joystick[1])
  259.    {
  260.       fg_setcolor(15);
  261.       fg_rect(340,520,100,190);
  262.       fg_setcolor(0);
  263.       draw_box(340,520,100,190);
  264.       draw_box(400,460,100,190);
  265.       draw_box(340,520,130,160);
  266.    }
  267.  
  268.    pos1 = 4; new_pos1 = pos1;
  269.    pos2 = 4; new_pos2 = pos2;
  270.  
  271.    /* draw red boxes to represent joystick straight up position */
  272.  
  273.    fg_setcolor(4);
  274.    if (joystick[0])
  275.    {
  276.       x = joy1_x[pos1];
  277.       y = joy_y[pos1];
  278.       fg_rect(x,x+20,y,y+10);
  279.    }
  280.    if (joystick[1])
  281.    {
  282.       x = joy2_x[pos2];
  283.       y = joy_y[pos2];
  284.       fg_rect(x,x+20,y,y+10);
  285.    }
  286.  
  287.    fg_mousevis(ON);
  288.    while (TRUE)
  289.    {
  290.       fg_waitfor(3);
  291.  
  292.       /* handle first joystick */
  293.  
  294.       if (joystick[0])
  295.       {
  296.          fg_intjoy(1,&key,&aux);
  297.          if (key == CR)
  298.             break;
  299.          if (aux == 0)
  300.             new_pos1 = 4;
  301.          else if (aux >= 71 && aux <= 73)
  302.             new_pos1 = aux - 71;
  303.          else if (aux >= 75 && aux <= 77)
  304.             new_pos1 = aux - 72;
  305.          else if (aux >= 79 && aux <= 81)
  306.             new_pos1 = aux - 73;
  307.  
  308.          if (new_pos1 != pos1)
  309.          {
  310.             fg_setcolor(15);
  311.             x = joy1_x[pos1];
  312.             y = joy_y[pos1];
  313.             fg_mousevis(OFF);
  314.             fg_rect(x,x+20,y,y+10);
  315.  
  316.             pos1 = new_pos1;
  317.             fg_setcolor(4);
  318.             x = joy1_x[pos1];
  319.             y = joy_y[pos1];
  320.             fg_rect(x,x+20,y,y+10);
  321.             fg_mousevis(ON);
  322.          }
  323.       }
  324.  
  325.       /* handle second joystick */
  326.  
  327.       if (joystick[1])
  328.       {
  329.          fg_intjoy(2,&key,&aux);
  330.          if (key == CR)
  331.             break;
  332.